package com.modbus;

import com.netty.modbus.handler.DataHandlerExample;
import com.netty.modbus.server.NettyServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * description: NettyCommandLineRunner <br>
 * date: 2021/9/27 9:14 <br>
 * @author: lwy <br>
 * @version: 1.0 <br>
 */
@Component
public class NettyCommandLineRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        new Thread(new Runnable() {
            @Override
            public void run() {
                //业务逻辑处理
                try {
                    NettyServer nettyServer=new NettyServer(30502,new DataHandlerExample());
                    nettyServer.start();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        },"netty服务线程").start();
    }
}
